package com.business_clean.app.flutter;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import com.business_clean.app.flutter.bean.BaseSerializableFlutterMap;
import com.business_clean.app.uitl.ActivityForwardUtil;
import com.business_clean.app.uitl.MMKVHelper;
import com.business_clean.ui.activity.login.LoginActivity;
import com.idlefish.flutterboost.EventListener;
import com.idlefish.flutterboost.FlutterBoost;

import java.util.Map;

/**
 * Flutter 发送给原生的通知
 */
public class BoostEventListener implements EventListener {


    @Override
    public void onEvent(String s, Map<String, Object> map) {
        Activity activity = FlutterBoost.instance().currentActivity();
        if (activity == null) {
            return;
        }
        Log.e(s, map.toString());
        if (map != null) {
            BaseSerializableFlutterMap serializableMap = new BaseSerializableFlutterMap();
            serializableMap.setMap(map);
            Bundle bundle = new Bundle();
            bundle.putSerializable("map", serializableMap);
            bundle.putBoolean("jump_flutter", true);
            String method = (String) map.get("method");
            switch (method) {
                case "login"://token 失效，去登录
                    MMKVHelper.clearAll();
                    ActivityForwardUtil.startActivity(LoginActivity.class);
                    break;
                default:
                    break;
            }
        }
    }


}
